package com.doumi.biz.qadev.api.util;

import java.io.*;

/**
 * Created by YDZ on 2019/11/7.
 */
public class OutInputUtil {
    public  String readToString(String fileName) {
        String encoding = "UTF-8";
        File file = new File(fileName);
        Long filelength = file.length();
        byte[] filecontent = new byte[filelength.intValue()];
        try {
            try (FileInputStream in = new FileInputStream(file)) {
                in.read(filecontent);
                in.close();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            return new String(filecontent, encoding);
        } catch (UnsupportedEncodingException e) {
            System.err.println("The OS does not support " + encoding);
            e.printStackTrace();
            return null;
        }
    }

    //将string转存成文本
    public void strChangeWord(String path,String str){
        try {
            OutputStreamWriter out =new OutputStreamWriter(new FileOutputStream(path));
            out.write(str);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
